package com.yinhe.music.yhmusic.adapter;

import android.widget.ImageView;

import com.chad.library.adapter.base.BaseSectionQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.common.GlideHelper.GlideHelper;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.comment.CommentSection;
import com.yinhe.music.yhmusic.model.CommentList;

import java.util.List;

/**
 * Created by hasee on 2017/8/15.
 */

public class CommentListAdapter extends BaseSectionQuickAdapter<CommentSection, BaseViewHolder> {

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CommentListAdapter(List<CommentSection> data) {
        super(R.layout.comment_item_layout, R.layout.comment_item_header, data);
    }

    @Override
    protected void convertHead(BaseViewHolder helper, CommentSection item) {
        helper.setText(R.id.header_text, item.header);
    }

    /**
     * Implement this method and use the helper to adapt the view to the given item.
     *
     * @param helper A fully initialized helper.
     * @param item   The item that needs to be displayed.
     */
    @Override
    protected void convert(BaseViewHolder helper, CommentSection item) {
        CommentList commentBean = item.t;
        helper.setText(R.id.user_name, commentBean.getNickname())
            .setText(R.id.comment_content, commentBean.getContent())
            .setText(R.id.comment_time, commentBean.getPublish_time())
            .setText(R.id.comment_like_num, String.valueOf(commentBean.getLikeNum()));
        ImageView userImage = helper.getView(R.id.user_pic);
        ImageView like = helper.getView(R.id.comment_like);
        GlideHelper.setCircleImageResource(userImage, commentBean.getimage(), R.drawable.ic_default_singer);
        if (commentBean.getCollectStatus() == 1) {
            like.setImageResource(R.drawable.ic_comment_islike);
        } else {
            like.setImageResource(R.drawable.ic_comment_like);
        }
        helper.addOnClickListener(R.id.comment_like);
    }
}
